// packageA/pages/changeFaMa/index.js
import http from '../../../utils/http';
import api from '../../../utils/api';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        radio1: false,
        radio2: false,
        rightEye1: '',
        leftEye1: '',
        rightEye2: '',
        leftEye2: '',
        child_id: "",
        childInfo: "",
        user_id: "",
    },
    init() {
        const childInfo = wx.getStorageSync('childInfo')
        const userInfo = wx.getStorageSync('userInfo')
        this.setData({
            child_id: childInfo.id ? childInfo.id : 0,
            childInfo: childInfo,
            user_id: userInfo.id,
            radio1: childInfo.if_father,
            radio2: childInfo.if_mother,
            rightEye1: childInfo.r_father,
            leftEye1: childInfo.l_father,
            rightEye2: childInfo.r_mother,
            leftEye2: childInfo.l_mother,
        })
    },
    onChangeRadio1(e) {
        this.setData({
            radio1: e.detail,
        });
    },
    onChangeRadio2(e) {
        this.setData({
            radio2: e.detail,
        });
    },
    handleSubmit() {
        http.putHttp(api.updateProfileInfo + this.data.child_id, {
                if_father: this.data.radio1,
                if_mother: this.data.radio2,
                r_father: this.data.rightEye1,
                l_father: this.data.leftEye1,
                r_mother: this.data.rightEye2,
                l_mother: this.data.leftEye2,
                user_id: this.data.user_id
            }, (result) => {
                if (result.code == 0) {
                    wx.showToast({
                        title: '修改成功',
                    })
                    wx.setStorageSync('child', result.data)
                    result.data.forEach(ele => {
                        if (ele.id == this.data.childInfo.id) {
                            wx.setStorageSync('childInfo', ele)
                            this.init()
                        }
                    })
                }

            },
            (err) => {
                console.log(err);
            },
        )
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.init()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})